#include "../voxelBase_0/volume3D.h"
#include "../voxelBase_0/volume3DHash.h"
#include "../voxelBase_0/sparseVoxelOctree.h"
#include "../voxelBase_0/octNode.h"

//#include "octreeVolume.h"
//#include <assert.h>
//
//#include "nodePool3D.h"
//#include "blockPool.h"


#define _DEBUG_MEMORY_LEAK

#ifdef _DEBUG_MEMORY_LEAK
	#define _CRTDBG_MAP_ALLOC
	#include <stdlib.h>
#include <crtdbg.h>
#endif

#include <iostream>
#include <stdio.h>

#pragma comment(lib,"glew32.lib")

int main()
{
/*
	volume3D<unsigned char> *vol = new volume3D<unsigned char>("output-zyx-960X1024X1024.raw", 960, 1024, 1024);
	if(!vol)
		exit(0);
	volume3D<unsigned char> *subVol = vol->generateDownSampleVolume();
	delete vol;
	subVol->writeToFile("downSampled");
	delete subVol;
 */
	volume3D<unsigned char> *vol = new volume3D<unsigned char>(256,256,256,100);
  vol->writeToFile("uniformVolume","./");
  exit(0);
	vol->addSphereRegion(100,100,100,50,255);
	vol->addSphereRegion(0,0,0,60,100);
	vol->addSphereRegion(150,150,0,100,50);
	//const char* path = "../../../octreeVolumeRenderer/Data/";
	const char* path = "../../../octreeVolumeRenderer/Data/";
	vol->writeToFile("sphere", path);

	
	volume3D<unsigned char> *vol1 = new volume3D<unsigned char>(3,3,3,0);
	//vol1->setVoxel(0,0,0,255);
	vol1->setVoxel(1,1,1,255);
	//vol1->setVoxel(2,2,0,255);
	//vol1->setVoxel(0,2,0,255);
	//vol1->setVoxel(2,0,0,255);
	//const char* path = "../../../octreeVolumeRenderer/Data/";
	vol1->writeToFile("Testcube", path);

	//voxel hash test

	//volume3DHash<unsigned char> *hashVol = new volume3DHash<unsigned char>(32,32,32,0,16); //32 16 almost the same time
	volume3DHash<unsigned char> *hashVol = new volume3DHash<unsigned char>(1000,1000,1000,0,16); //32 16 almost the same time

	for(int i=50; i<500; i++)
		for(int j=100; j<200; j++)
			for(int k=0; k<9; k++)
	//for(int i=17; i<32; i++)
	//	for(int j=17; j<32; j++)
	//		for(int k=0; k<32; k++)
			{
				hashVol->addVoxel(i,j,k,200)	;
			}

	printf("insertion finished!\n");
	sparseVoxelOctree<unsigned char> svo = sparseVoxelOctree<unsigned char>();
	svo.createOVFromHashVolume(hashVol);
	svo.DFS();


	//for(int i=200; i<300; i++)
	//	for(int j=200; j<300; j++)
	//		for(int k=100; k<300; k++)
	//		{
	//			printf("%d ",hashVol->getVoxel(i,j,k));	
	//		}			
	//hashVol->convertToRawVolume();
	//hashVol->writeToFile("testVolume",path);
			//8M is really fast for construction 
			//test the lookup
		


	return 0;
} 